import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

import '../colors.dart';

class RowBanner extends StatelessWidget {

  final List data;

  RowBanner(this.data);

  @override
  Widget build(BuildContext context) {
    final imageWidth = MediaQuery.of(context).size.width - 15 * 2;
    final height = imageWidth * 0.3888 + 15;
    //Swiper控件在ListView中使用时需要提前指定高度？？？
    return Container(
      height: height,
      color: ProjectColors.CARD_DARK,
      child: Swiper(
        itemBuilder: (context, index) {
          return ItemBanner(data[index]);
        },
        itemCount: data.length,
        autoplay: true,
      ),
    );
  }

}

class ItemBanner extends StatelessWidget {

  final Map<String, dynamic> _itemData;

  ItemBanner(this._itemData);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(15, 15,15,0),
      child: ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(8)),
          child: Stack(
            children: [
              Image.network(_itemData['pic'], fit: BoxFit.cover),
              _getLabel()
            ],
          )),
    );
  }

  Widget _getLabel() {
    return Positioned(
      right: 0,
      bottom: 0,
      child: Container(
        decoration: BoxDecoration(
            color: Colors.redAccent,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(8),
                bottomRight: Radius.circular(8))),
        padding: EdgeInsets.fromLTRB(10, 2, 10, 2),
        child: Text(
          _itemData['typeTitle'],
          style: TextStyle(color: Colors.white, fontSize: 16),
        ),
      ),
    );
  }
}